In the event of technical difficulties with Szkopuł, please contact us via email at [email protected].
If you would like to talk about tasks, solutions or technical problems, please visit our Discord servers. They are moderated by the community, but members of the support team are also active there.
Byteland is known for wandering flea trainers. Tamed fleas are taught to dance. They make precise leaps in the rhythm of music. On the table the trainer puts in a row numbered coins, but it's not assumed that they are arranged in any specific order. On each coin there is an inscription of the form ""; is the number of this coin and is the number of the coin on which a flea should leap if it sits on this coin. Then the trainer puts one flea on each coin and turns on the music. The fleas, while dancing, follow the rhythm of the music; i.e. at each beat of music each flea leaps directly to the coin with number equal to the -number written on the coin it is sitting on. During the dance it may happen that many fleas sit on the same coin. In this case they continue their performance together. Let's assume that we have coins and fleas. As soon as we say what numbers are written on the coins , we will have the performance fully determined. However, two different sets of coins may give the same performance, if only we arrange them in appropriate order.
Let us consider the performance on three coins. If the leaps are performed in the following way: from the first coin to the second one, from the second coin to the third one, from the third coin to the first one (we denote this: ); then the fleas will dance in a circle and no two of them will ever meet on one coin. For example, the dance is different, because it will make all the fleas meet on the third coin after two beats of music and it will make them jump only on the third coin forever.
However, the sets and are of the same type. If you put these coins in the row - the first set from left to right and the second from right to left - you would see the same performance.
In the first line of the standard input there is written one integer equal to the number of test cases, . In the following lines the test cases are described - each case occupies three consecutive lines. The first of these three contains one integer , , equal to the number of coins. Each of the remaining two lines is a description of a set of coins in a form of integers from the interval , separated by single spaces; the -th integer denotes the number of a coin that flea must leap to when it seats on the -th coin.
For each of the test cases from the input your program should write to the standard output exactly one line containing exactly one letter:
For the input data:
2 3 2 3 1 2 3 3 4 2 3 2 4 1 3 2 3
the correct result is:
N T
Task author: Marcin Sawicki.